package com.sunfeng.n4;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author sunfeng
 * @date 2021/03/26 09:37
 **/
@Slf4j(topic = "c.WaitNotify")
public class WaitNotify {
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();
        new Thread(()->{

            synchronized (object){
                log.debug("开始进入等待");
                try {
                    object.wait();
                    log.debug("等待结束");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }

        },"WaitThread").start();

        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{

            synchronized (object){
                log.debug("开始唤醒");
                object.notifyAll();
            }

        },"NotifyThread").start();

    }
}
